//
//  DevDetailViewController.m
//  WifiApp
//
//  Created by liao Echo on 14-11-3.
//  Copyright (c) 2014年 Echo. All rights reserved.
//

#import "DevDetailViewController.h"
#import "PokerControlClient.h"
#import "DDAlertPrompt.h"
#import "RecInfo.h"


@interface DevDetailViewController ()<UITextFieldDelegate>{
    UITextField *textField1, *textField2, *textField3, *textField4, *textField5, *textField6;
}

@end

@implementation DevDetailViewController
@synthesize type, string;
//0406513F9E   3F9E 0651
-(void)setLabel:(UILabel*)label string:(NSString*)nextstr{
    unsigned tempi;
    NSString *mutString = [nextstr substringFromIndex:2];
    NSString *str1 = [mutString substringFromIndex:4];
    NSString *str2 = [mutString substringToIndex:4];
    NSString *string1 = [NSString stringWithFormat:@"%@%@", str1, str2];
    NSScanner *scanner = [NSScanner scannerWithString:string1];
    [scanner scanHexInt:&tempi];
    float *tempf = (float *)&tempi;
    label.text = [NSString stringWithFormat:@"%.2f", *tempf];
}
-(void)setnIntLabel:(UILabel*)label string:(NSString*)nextstr{
//    nextstr = @"0419330000";
    unsigned int tempf;
    NSString *mutString = [nextstr substringFromIndex:2];
    NSString *str1 = [mutString substringFromIndex:4];
    NSString *str2 = [mutString substringToIndex:4];
    NSString *string1 = [NSString stringWithFormat:@"%@%@", str1, str2];
    NSScanner *scanner = [NSScanner scannerWithString:string1];
    [scanner scanHexInt: &tempf];
    label.text = [NSString stringWithFormat:@"%d", tempf];
}

- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex {
    if (buttonIndex != [alertView cancelButtonIndex])
    {
        DDAlertPrompt *loginPrompt = (DDAlertPrompt *)alertView;
        NSString *groupName = loginPrompt.plainTextField.text;
        if ([groupName isEqualToString:@"118800"]) {
            NSString *str = @"<app_management";
            if ([textField1.text length] > 0) {
                str = [str stringByAppendingFormat:@" unit=\"%@\"", textField1.text];
            }else{
                str = [str stringByAppendingFormat:@" unit=\"%@\"", @""];
            }
            if ([textField2.text length] > 0) {
                str = [str stringByAppendingFormat:@" department=\"%@\"", textField2.text];
            }else{
                str = [str stringByAppendingFormat:@" department=\"%@\"", @""];
            }
            if ([textField3.text length] > 0) {
                str = [str stringByAppendingFormat:@" head=\"%@\"", textField3.text];
            }else{
                str = [str stringByAppendingFormat:@" head=\"%@\"", @""];
            }
            if ([textField4.text length] > 0) {
                str = [str stringByAppendingFormat:@" serinum=\"%@\"", textField4.text];
            }else{
                str = [str stringByAppendingFormat:@" serinum=\"%@\"", @""];
            }
            if ([textField5.text length] > 0) {
                str = [str stringByAppendingFormat:@" note=\"%@\"", textField5.text];//wei
            }else{
                str = [str stringByAppendingFormat:@" note=\"%@\"", @""];
            }
            if ([textField6.text length] > 0) {
                str = [str stringByAppendingFormat:@" item=\"%@\"", textField6.text];
            }else{
                str = [str stringByAppendingFormat:@" item=\"%@\"", @""];
            }
            str = [str stringByAppendingFormat:@" %@", @"/>"];
            //    [[PokerControlClient share] startCmd:@"2" code:[NSString stringWithFormat:@"<app_data unit=\"%@\"  department=\"%@\" head=\"%@\" serinum=\"%@\" note =\"%@\" item=\"%@\"  />", textField1.text,textField2.text,textField3.text,textField4.text,textField5.text,textField6.text]];
            
            [[PokerControlClient share] startCmd:@"2" code:str];
            
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"密码错误" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
        }
    }
}
- (void)save{
    DDAlertPrompt *loginPrompt = nil;
    loginPrompt = [[DDAlertPrompt alloc] initWithTitle:@"请输入密码" delegate:self cancelButtonTitle:@"取消" otherButtonTitle:@"确定" content:@""];
    [loginPrompt show];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    
//    self.title = STR(@"管理信息");
    
    [NC addObserver:self selector:@selector(app_management:) name:NOTI_app_management_INFO object:nil];
    
    if (type == 1) {//管理信息
        
        [[PokerControlClient share] startCmd:@"1" code:nil];
        UIBarButtonItem *right = [[UIBarButtonItem alloc] initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:self action:@selector(save)];
        self.navigationItem.rightBarButtonItem = right;
        
    }else if (type == 2) {//流量信息
        [[PokerControlClient share] startCmd:@"0" code:@"<app_data addr0=\"00000002\"  addr1=\"00060002\" addr2=\"00080002\" addr3=\"000b0002\" addr4=\"000e0002\" addr5=\"000a0001\" addr6=\"000d0001\" addr7=\"00100001\" addr8=\"003b0002\" addr9=\"003f0001\"  addr10=\"003d0002\" addr11=\"00020002\" addr12=\"00040002\" />"];
    }else if (type == 3) {//能量信息
        [[PokerControlClient share] startCmd:@"0" code:@"<app_data addr0=\"00490002\"  addr1=\"004b0002\" addr2=\"00140002\" addr3=\"004d0002\" addr4=\"00500002\" addr5=\"00110002\" addr6=\"004f0001\" addr7=\"00520001\" addr8=\"00130001\" addr9=\"00400002\"  addr10=\"00420001\"  />"];
    }else if (type == 4) {//产品信息
        [[PokerControlClient share] startCmd:@"0" code:@"<app_data addr0=\"00430002\"  addr1=\"00450004\" addr2=\"001d0003\" addr3=\"00160002\" addr4=\"00180002\" addr5=\"001a0001\" addr6=\"001b0002\" />"];
    }else if (type == 5) {//导出信息
        [[PokerControlClient share] startCmd:@"3" code:@"<app_data addr0=\"00430002\"  addr1=\"00450004\" addr2=\"001d0003\" addr3=\"00160002\" addr4=\"00180002\" addr5=\"001a0001\" addr6=\"001b0002\" />"];
    }
    
    
    [self initTabview];
    tabview.delegate = self;
    tabview.dataSource = self;
}
-(void)dealloc{
    [NC removeObserver:self];
}
-(void)app_management:(NSNotification*)noti{
    self.string = noti.object;
    [tabview reloadData];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (type == 3) {
        return 7;
    }else if (type == 4) {
        return 8;
    }else if (type == 1) {
        return 7;
    }
    return 6;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 64;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"TableView1Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    cell.textLabel.textAlignment = UITextAlignmentLeft;
    cell.textLabel.font = [UIFont systemFontOfSize:17];
    cell.textLabel.textColor = [UIColor blackColor];
    
    if (indexPath.row == 0) {
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.textLabel.font = [UIFont boldSystemFontOfSize:20];
        cell.textLabel.textAlignment = UITextAlignmentCenter;
        
        if (type == 1) {
            cell.textLabel.text = @"管理信息";
        }else if (type == 2) {
            cell.textLabel.text = @"流量信息";
        }else if (type == 3) {
            cell.textLabel.text = @"能量信息";
        }else if (type == 4) {
            cell.textLabel.text = @"产品信息";
        }
    }
    
    if (type == 1) {//管理
        [self initGuanli:cell cellForRowAtIndexPath:indexPath];
    }else if (type == 2) {//流量
        [self initLiuliang:cell cellForRowAtIndexPath:indexPath];
    }else if (type == 3) {//能量
        [self initNengliang:cell cellForRowAtIndexPath:indexPath];
    }else if (type == 4) {//产品
        [self initChanpin:cell cellForRowAtIndexPath:indexPath];
    }

    
    cell.backgroundColor = [UIColor clearColor];
    return cell;
}

-(void)initChanpin:(UITableViewCell *)cell cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(135, 0, SCREEN_WIDTH-135-10, 64)];
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    [cell.contentView addSubview:label];
    
    if(indexPath.row == 1){
        cell.textLabel.text = @"产品地址 ： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data0=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            
            [self setnIntLabel:label string:nextstr];
        }
    }else if(indexPath.row == 2){
        cell.textLabel.text = @"序列号： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data1=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            label.text = [RecInfo getString:label.text];
        }
    }else if(indexPath.row == 3){
        cell.textLabel.text = @"错误代码： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data2=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            label.text = [RecInfo getString:label.text];
        }
    }else if(indexPath.row == 4){
        cell.textLabel.text = @"上游信号： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data3=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setLabel:label string:nextstr];
        }
    }else  if(indexPath.row == 5){
        cell.textLabel.text = @"下游信号：  ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data4=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setLabel:label string:nextstr];
        }
    }else  if(indexPath.row == 6){
        cell.textLabel.text = @"信号质量：  ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data5=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setnIntLabel:label string:nextstr];
        }
    }else  if(indexPath.row == 7){
        cell.textLabel.text = @"输出(4-20mA)：  ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data6=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setLabel:label string:nextstr];
        }
    }
}
-(void)initLiuliang:(UITableViewCell *)cell cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, SCREEN_WIDTH-100-10, 64)];
    label.adjustsFontSizeToFitWidth = YES;
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    [cell.contentView addSubview:label];
    
    if(indexPath.row == 1){
        cell.textLabel.text = @"瞬时流量 ： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data0=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setLabel:label string:nextstr];
            
            range = [string rangeOfString:@"data10=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
//            label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  [RecInfo getString:nextstr]];
            NSString *danwei = [RecInfo getString:nextstr];
            
            if ([danwei hasSuffix:@"s"]) {
                
                [self setLabel:label string:nextstr];
                
                label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  danwei];//瞬时流量
            }else if ([danwei hasSuffix:@"m"]) {
                
                range = [string rangeOfString:@"data11=\""];
                nextstr = [string substringFromIndex:range.location+range.length];
                range1 = [nextstr rangeOfString:@"\""];
                nextstr = [nextstr substringToIndex:range1.location];
                [self setLabel:label string:nextstr];
                
                label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  danwei];//瞬时流量
            }else{
                
                range = [string rangeOfString:@"data12=\""];
                nextstr = [string substringFromIndex:range.location+range.length];
                range1 = [nextstr rangeOfString:@"\""];
                nextstr = [nextstr substringToIndex:range1.location];
                
                [self setLabel:label string:nextstr];
                
                label.text = [NSString stringWithFormat:@"%@ (%@)", label.text, danwei];//瞬时流量
            }
        }
    }else if(indexPath.row == 2){
        cell.textLabel.text = @"流速： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data1=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setLabel:label string:nextstr];
            
            
            range = [string rangeOfString:@"data8=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  [RecInfo getString:nextstr]];
        }
    }else if(indexPath.row == 3){
        cell.textLabel.text = @"正累积量： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data2=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            
            [self setnIntLabel:label string:nextstr];
            
            range = [string rangeOfString:@"data5=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@×%@", label.text, [RecInfo getInt:nextstr]];
            
            range = [string rangeOfString:@"data9=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  [RecInfo getString:nextstr]];
        }
    }else if(indexPath.row == 4){
        cell.textLabel.text = @"负累积量： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data3=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            [self setnIntLabel:label string:nextstr];
            
            
            range = [string rangeOfString:@"data6=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@×%@", label.text, [RecInfo getInt:nextstr]];
            
            range = [string rangeOfString:@"data9=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  [RecInfo getString:nextstr]];
        }
    }else  if(indexPath.row == 5){
        cell.textLabel.text = @"净累积量：  ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data4=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            [self setnIntLabel:label string:nextstr];
            
            range = [string rangeOfString:@"data7=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@×%@", label.text, [RecInfo getInt:nextstr]];
            
            range = [string rangeOfString:@"data9=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  [RecInfo getString:nextstr]];
        }
    }
}
-(void)initNengliang:(UITableViewCell *)cell cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(130, 0, SCREEN_WIDTH-130-10, 64)];
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    [cell.contentView addSubview:label];
    
    if(indexPath.row == 1){
        cell.textLabel.text = @"进水温度 ： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data0=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setLabel:label string:nextstr];
            
        }
    }else if(indexPath.row == 2){
        cell.textLabel.text = @"出水温度： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data1=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setLabel:label string:nextstr];
        }
    }else if(indexPath.row == 3){
        cell.textLabel.text = @"瞬时能量： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data2=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setLabel:label string:nextstr];
            
            range = [string rangeOfString:@"data9=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  [RecInfo getString:nextstr]];
        }
    }else if(indexPath.row == 4){
        cell.textLabel.text = @"热量累积量： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data3=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            
            [self setnIntLabel:label string:nextstr];
            
            range = [string rangeOfString:@"data6=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@×%@", label.text, [RecInfo getInt:nextstr]];
            
            range = [string rangeOfString:@"data10=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  [RecInfo getString:nextstr]];
            
        }
    }else  if(indexPath.row == 5){
        cell.textLabel.text = @"冷量累积量：  ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data4=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setnIntLabel:label string:nextstr];
            
            range = [string rangeOfString:@"data7=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@×%@", label.text, [RecInfo getInt:nextstr]];
            
            range = [string rangeOfString:@"data10=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  [RecInfo getString:nextstr]];
            
        }
    }else  if(indexPath.row == 6){
        cell.textLabel.text = @"能量累积量：  ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"data5=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            [self setnIntLabel:label string:nextstr];
            
            range = [string rangeOfString:@"data8=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@×%@", label.text, [RecInfo getInt:nextstr]];
            
            range = [string rangeOfString:@"data10=\""];
            nextstr = [string substringFromIndex:range.location+range.length];
            range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = [NSString stringWithFormat:@"%@ (%@)", label.text,  [RecInfo getString:nextstr]];
        }
    }
}
-(void)initGuanli:(UITableViewCell *)cell cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 0, SCREEN_WIDTH-100-10, 64)];
    label.hidden = YES;
    label.numberOfLines = 0;
    label.backgroundColor = [UIColor clearColor];
    [cell.contentView addSubview:label];
    
    UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 0, SCREEN_WIDTH-100-10, 64)];
    textField.delegate = self;
    textField.backgroundColor = [UIColor clearColor];
    [cell.contentView addSubview:textField];
    
    if(indexPath.row == 1){
        cell.textLabel.text = @"单位 ： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"unit=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            textField1 = textField;
        }
    }else if(indexPath.row == 2){
        cell.textLabel.text = @"部门： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"department=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            textField2 = textField;
        }
    }else if(indexPath.row == 3){
        cell.textLabel.text = @"负责人： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"head=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            textField3 = textField;
        }
    }else  if(indexPath.row == 4){
        cell.textLabel.text = @"位号：  ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"item=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            textField6 = textField;
        }
    }else if(indexPath.row == 5){
        cell.textLabel.text = @"序列号： ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"serinum=\""];
            NSString *nextstr = [string substringFromIndex:range.location+range.length];
            NSRange range1 = [nextstr rangeOfString:@"\""];
            nextstr = [nextstr substringToIndex:range1.location];
            label.text = nextstr;
            
            textField4 = textField;
        }
    }else  if(indexPath.row == 6){
        cell.textLabel.text = @"备注：  ";
        if ([string length] > 0) {
            NSRange range = [string rangeOfString:@"note=\""];
            if (range.location != NSNotFound) {
                NSString *nextstr = [string substringFromIndex:range.location+range.length];
                NSRange range1 = [nextstr rangeOfString:@"\""];
                nextstr = [nextstr substringToIndex:range1.location];
                label.text = nextstr;
            }else{
                NSRange range = [string rangeOfString:@"note =\""];
                if (range.location != NSNotFound) {
                    NSString *nextstr = [string substringFromIndex:range.location+range.length];
                    NSRange range1 = [nextstr rangeOfString:@"\""];
                    nextstr = [nextstr substringToIndex:range1.location];
                    label.text = nextstr;
                }
            }
            textField5 = textField;
        }
    }
    
    textField.text = label.text;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField{
    if (textField == textField1) {
        
    }else if (textField == textField2) {
        
    }else if (textField == textField3) {
        tabview.frame = CGRectMake(0, -70, SCREEN_WIDTH, SCREEN_HEIGHT-64);
    }else if (textField == textField4) {
        tabview.frame = CGRectMake(0, -(300-30)+50, SCREEN_WIDTH, SCREEN_HEIGHT-64);
    }else if (textField == textField5) {
        tabview.frame = CGRectMake(0, -(300-20)+50, SCREEN_WIDTH, SCREEN_HEIGHT-64);
    }else if (textField == textField6) {
        tabview.frame = CGRectMake(0, -300+50, SCREEN_WIDTH, SCREEN_HEIGHT-64);
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    [textField1 resignFirstResponder];
    [textField2 resignFirstResponder];
    [textField3 resignFirstResponder];
    [textField4 resignFirstResponder];
    [textField5 resignFirstResponder];
    [textField6 resignFirstResponder];
    
    tabview.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-64);
    
}

@end
